package com.wen.common.utils;

import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@ToString
@Component
@PropertySource("classpath:/wx.properties")
public class WeChatUtil {

    @Value("${appid}")
    private String appId;

    @Value("${secret}")
    private String secret;

    private String TokenUrl;

    private static String PermanentMaterialUrl;

    private final String permanentMaterialString;

    public WeChatUtil() {
        this.permanentMaterialString = "{\n" +
                "    \"type\":\"news\",\n" +
                "    \"offset\":0,\n" +
                "    \"count\":2\n" +
                "}";
    }

//    @Value("${appid}")
//    public static void setAppId(String appId) {
//        this.appId = appId;
//    }
//
//    @Value("${secret}")
//    public static void setSecret(String secret) {
//        WeChatUtil.secret = secret;
//    }

    @Value("${PermanentMaterialUrl}")
    public void setPermanentMaterialUrl(String permanentMaterialUrl) {
        PermanentMaterialUrl = permanentMaterialUrl;
    }


    public String getAppId() {
        return appId;
    }

    public String getSecret() {
        return secret;
    }

    public String getPermanentMaterialUrl() {
        return PermanentMaterialUrl;
    }

    public String getTokenUrl() {
        this.TokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
                + appId + "&secret=" + secret;
        return TokenUrl;
    }

    public String getPermanentMaterialString() {
        return permanentMaterialString;
    }

}
